package com.taru.university.service.impl;

import com.github.pagehelper.PageHelper;
import com.taru.university.mapper.CommentMapper;
import com.taru.university.mapper.ExchangeMapper;
import com.taru.university.model.Comment;
import com.taru.university.model.Exchange;
import com.taru.university.service.ExchangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExchangeServiceImpl implements ExchangeService {
    @Autowired
    ExchangeMapper exchangeMapper;
    @Autowired
    CommentMapper commentMapper;

    @Override
    public List<Exchange> queryExchange(int pageNum, int pageSize) {
        List<Exchange> list = exchangeMapper.queryExchange();
        PageHelper.startPage(pageNum, pageSize);
        for(Exchange exchangeList : list){
            List<Comment> commentList = commentMapper.queryCommentByArticleId(exchangeList.getExchangeId());
            exchangeList.setCommentList(commentList);
        }
        return list;
    }

    @Override
    public List<Exchange> queryExchangeLen( ) {
        return exchangeMapper.queryExchange();
    }

    @Override
    public Exchange queryExchangeById(String exchangeId) {
        return exchangeMapper.queryExchangeById(exchangeId);
    }

    @Override
    public void insertExchange(Exchange exchange) {
        exchangeMapper.insertExchange(exchange);
    }

    @Override
    public void deleteExchange(String exchangeId) {
        exchangeMapper.deleteExchange(exchangeId);
    }
}
